package com.hezuti.sns.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;

import com.hezuti.common.utils.CookieUtil;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class RightCheck extends AbstractInterceptor {

	private static final Log log = LogFactory.getLog(RightCheck.class);
	
	private String failedStr;
	
	/**
	 * 拦截器方法
	 */
	@Override
	public String intercept(ActionInvocation arg0) throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		String uid=CookieUtil.getValueFromCookies(request, "id");
		if(uid!=null&&null!=session.getAttribute(uid)){
			//已经登录
			//验证权限
			return arg0.invoke();
		}else{
			return failedStr;
			}
	}

	public String getFailedStr() {
		return failedStr;
	}

	public void setFailedStr(String failedStr) {
		this.failedStr = failedStr;
	}

}
